package com.geeklan.smart.ui.viewmodel.device;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.geeklan.smart.data.model.Device;
import com.geeklan.smart.data.repository.RepositoryCallback;
import com.geeklan.smart.data.repository.device.CmdRepository;

public class CmdViewModel extends ViewModel {
    private final CmdRepository cmdRepository;
    private MutableLiveData<Device> cmdLiveData = new MutableLiveData<>();
    private MutableLiveData<String> errorLiveData = new MutableLiveData<>();

    public CmdViewModel(CmdRepository userRepository) {
        this.cmdRepository = userRepository;
    }

    public void loadUser(String userId) {
        cmdRepository.sendCmd(userId, new RepositoryCallback<Device>() {
            @Override
            public void onSuccess(Device data) {
                if (data != null) {
                    cmdLiveData.setValue(data);
                }
            }

            @Override
            public void onError(Exception e) {
                errorLiveData.setValue(e.getMessage());
            }
        });
    }

    public LiveData<Device> getCmdLiveData() {
        return cmdLiveData;
    }

    public LiveData<String> getErrorLiveData() {
        return errorLiveData;
    }
}
